home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_defaulteditroutine.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  164 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <intuition/sghooks.h>    /* For struct SGWork */
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24. ULONG SAVE_DS ASM
  25. LTP_DefaultEditRoutine(REG(a0) struct Hook *Hook,REG(a2) struct SGWork *Work,REG(a1) Msg msg)
  26. {
  27.     struct Hook *Validate;
  28.     LayoutHandle *Handle;
  29.     ObjectNode *Node;
  30.     BOOL Reject;
  31.  
  32.     if(!GETOBJECT(Work->Gadget,Node))
  33.         return(TRUE);
  34.  
  35.     switch(msg->MethodID)
  36.     {
  37.         case SGH_KEY:
  38.  
  39.             Handle = Hook->h_Data;
  40.  
  41.             if(Work->IEvent->ie_Code == 0x5F && Handle->HelpHook)
  42.             {
  43.                 Work->Code        = 0x5F;
  44.                 Work->Actions    = (Work->Actions & ~SGA_BEEP) | SGA_END | SGA_USE;
  45.  
  46.                 LTP_AddHistory(Work);
  47.                 break;
  48.             }
  49.  
  50.             if(Work->IEvent->ie_Code == CURSORUP || Work->IEvent->ie_Code == CURSORDOWN)
  51.                 LTP_HandleHistory(Work);
  52.  
  53.             if(Work->EditOp == EO_ENTER)
  54.             {
  55.                 BOOL Activate = TRUE;
  56.  
  57.                 DB(kprintf("enter operation\n"));
  58.  
  59.                 if(Node->Type == STRING_KIND)
  60.                 {
  61.                     if(Node->Special.String.LastGadget)
  62.                         Activate = FALSE;
  63.                 }
  64.                 else
  65.                 {
  66.                     #ifndef DO_HEXHOOK
  67.                     {
  68.                         if(Node->Type == INTEGER_KIND)
  69.                         {
  70.                             if(Node->Special.Integer.LastGadget)
  71.                                 Activate = FALSE;
  72.                         }
  73.                     }
  74.                     #endif /* DO_HEXHOOK */
  75.                 }
  76.  
  77.                 if(!(Work->IEvent->ie_Qualifier & QUALIFIER_SHIFT))
  78.                 {
  79.                     DB(kprintf("no shift\n"));
  80.  
  81.                     if(Activate && Handle->AutoActivate)
  82.                         Work->Actions |= SGA_NEXTACTIVE;
  83.  
  84.                     if(!(Work->Actions & SGA_NEXTACTIVE))
  85.                         Work->Code = '\r';
  86.                 }
  87.                 else
  88.                     DB(kprintf("has shift\n"));
  89.             }
  90.  
  91.             Reject = FALSE;
  92.  
  93.             if(Node->Type == FRACTION_KIND && (Work->EditOp == EO_INSERTCHAR || Work->EditOp == EO_REPLACECHAR))
  94.             {
  95.                 LONG DecimalPoint = LTP_DecimalPoint[0];
  96.  
  97.                 if(Work->Code == DecimalPoint || Work->Code == '.' || (Work->Code >= '0' && Work->Code <= '9'))
  98.                 {
  99.                     if(Work->Code == DecimalPoint || Work->Code == '.')
  100.                     {
  101.                         LONG i;
  102.  
  103.                         for(i = 0 ; i < Work->NumChars ; i++)
  104.                         {
  105.                             if(Work->PrevBuffer[i] == DecimalPoint)
  106.                             {
  107.                                 Reject = TRUE;
  108.                                 break;
  109.                             }
  110.                         }
  111.                     }
  112.                 }
  113.                 else
  114.                     Reject = TRUE;
  115.  
  116.                 if(!Reject && Work->Code == '.' && Work->Code != DecimalPoint)
  117.                 {
  118.                     LONG i;
  119.  
  120.                     for(i = 0 ; i < Work->NumChars ; i++)
  121.                     {
  122.                         if(Work->WorkBuffer[i] == '.')
  123.                         {
  124.                             Work->WorkBuffer[i] = DecimalPoint;
  125.                             break;
  126.                         }
  127.                     }
  128.                 }
  129.             }
  130.  
  131.             if(Node->Type == INTEGER_KIND)
  132.                 Validate = Node->Special.Integer.ValidateHook;
  133.             else
  134.                 Validate = Node->Special.String.ValidateHook;
  135.  
  136.             if(Validate)
  137.             {
  138.                 if(!CallHookPkt(Validate,Work,msg))
  139.                     Reject = TRUE;
  140.             }
  141.  
  142.             if(Reject)
  143.             {
  144.                 Work->EditOp    = EO_BADFORMAT;
  145.                 Work->Actions    = SGA_BEEP;
  146.             }
  147.  
  148.             if(Work->Actions & SGA_END)
  149.                 LTP_AddHistory(Work);
  150.  
  151.             /* Falls through to... */
  152.  
  153.         case SGH_CLICK:
  154.  
  155.             break;
  156.  
  157.         default:
  158.  
  159.             return(FALSE);
  160.     }
  161.  
  162.     return(TRUE);
  163. }
  164.